home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / programming / c / turbotext / scmsg_rendezvous.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1978-11-24  |  3.9 KB  |  169 lines

  1. /** $VER: scmsg_rendezvous 1.1 (20.12.92)
  2.  **                        1.0 (16.12.92)
  3.  **
  4.  ** A `rendezvous' rexx script for SAS/C's scmsg browser and TurboText.
  5.  ** There's no need to (nor is it intended) run this script directly, as
  6.  ** the supplied SCMSG configuration file will do it for you, if SCMSG
  7.  ** cannot locate the SCMSG_TTX_RENDEZVOUS message port.  Nice job, SAS.
  8.  **
  9.  ** Written by Kari Sutela
  10.  **/
  11.  
  12. options results
  13.  
  14. /*
  15.  * We absolutely need rexxsupport.library for this to work.
  16.  */
  17. if ~Show('L','rexxsupport.library') then do
  18.     if ~AddLib('rexxsupport.library',0,-30,0) then do
  19.         say 'Cannot AddLib rexxsupport.library'
  20.         exit 20
  21.     end
  22. end
  23. /*
  24.  * We need rexxarplib.library for some warning/error messages.
  25.  */
  26. if ~Show('L','rexxarplib.library') then do
  27.     if ~AddLib('rexxarplib.library',0,-30,0) then do
  28.         say 'Cannot AddLib rexxarplib.library (version 3.0)'
  29.         exit 20
  30.     end
  31. end
  32.  
  33. /*
  34.  * Open the rendezvous port
  35.  */
  36. port = 'SCMSG_TTX_RENDEZVOUS'
  37. if ~OpenPort(port) then do
  38.     say 'Cannot OpenPort('port')!'
  39.     exit 20
  40. end
  41.  
  42. goaway=0
  43. do until goaway
  44.     call WaitPkt(port)
  45.     packet = GetPkt(port)
  46.     if packet = Null() then do
  47.         iterate
  48.     end
  49.     cmd = GetArg(packet,0)
  50.     parse value cmd WITH cmd param '0d'x .
  51.     cmd = upper(cmd)
  52.     select
  53.         when cmd = 'QUIT' then do
  54.             call Reply(packet,0)
  55.             goaway = 1
  56.         end
  57.         when cmd = 'GOTOFILE' then do
  58.             /* GOTOLINE handles opening the file, too */
  59.             call Reply(packet,0)
  60.         end
  61.         when cmd = 'GOTOLINE' then do
  62.             /*
  63.              * The filename might contain blanks in which case SCMSG seems to
  64.              * automatically enclose it in quotes (this is not a documented
  65.              * feature, though).
  66.              */
  67.             if Words(param) > 2 then
  68.                 parse value param WITH '"'file'"' line .
  69.             else
  70.                 parse value param WITH file line .
  71.             call Reply(packet,0)
  72.             call TTX_it(file,line)
  73.         end
  74.         otherwise
  75.             call Reply(packet,10)
  76.     end
  77. end
  78. exit /* That's it! */
  79.  
  80. tail: PROCEDURE
  81.  
  82.     parse arg filename
  83.  
  84.     sep = lastpos('/',filename)
  85.     if sep = 0 then
  86.         sep = lastpos(':',filename)
  87.     if sep = 0 then
  88.         return filename
  89.     return substr(filename,sep+1)
  90.  
  91. activateline: PROCEDURE
  92.  
  93.     parse arg port, line
  94.  
  95.     address value port
  96.     'Move' line
  97.     /* Uniconify window to ensure visibility */
  98.     'GetWindowInfo'
  99.     parse value result WITH icon wleft wtop wwidth wheight .
  100.     if icon = 'ON' then do
  101.         'IconifyWindow OFF'
  102.         'GetWindowInfo'
  103.         parse value result WITH icon wleft wtop wwidth wheight .
  104.     end
  105.     'CenterView'
  106.     'GetScreenInfo'
  107.     parse value result WITH sleft stop stotalwidth stotalheight . svisiblewidth svisibleheight .
  108.     /* Is it mostly offscreen? */
  109.     offscreen = 0
  110.     sleft = -sleft; stop = -stop
  111.     wright = wleft+wwidth; wbot = wtop+wheight;
  112.     /* Calculate visible area */
  113.     if wleft > sleft then
  114.         visiblex = max((sleft + svisiblewidth) - wleft, 0)
  115.     else
  116.         visiblex = max((wleft + wwidth) - sleft, 0)
  117.     if wtop > stop then
  118.         visibley = max((stop + svisibleheight) - wtop, 0)
  119.     else
  120.         visibley = max((wtop + wheight) - stop, 0)
  121.     visible = visiblex*visibley
  122.     wsize = wwidth*wheight
  123.     /* Let's say that it's offscreen if 1/2 or less is visible */
  124.     if visible/wsize <= 0.5 then
  125.         call Request(sleft,stop,'scmsg_rendezvous WARNING:\  TTX window mostly offscreen!',,,'OK')
  126.     /* TTX window to front */
  127.     'Window2Front'
  128.     /* And scmsg over it */
  129.     address SC_SCMSG 'show'
  130.     /* Activate TTX window */
  131.     'ActivateWindow'
  132.     return
  133.  
  134.  
  135. TTX_it: PROCEDURE
  136.  
  137.     parse arg filename, line
  138.  
  139.     filepart = tail(filename)
  140.     /* TTX's GetPort does not properly handle non-unique documents */
  141.     address TURBOTEXT
  142.     'GetDocuments'
  143.     docs = result
  144.     do until docs = ''
  145.         parse value docs WITH '"'docfile'"' port docs
  146.         if docfile = filepart then do
  147.             address value port
  148.             'GetFilePath'
  149.             docfile = result
  150.             if docfile = filename then do
  151.                 call activateline(port,line)
  152.                 return
  153.             end
  154.         end
  155.     end
  156.  
  157.     /* Got here, so we should open the file */
  158.     address TURBOTEXT
  159.     'OpenDoc NAME' filename
  160.     if rc ~= 0 then do
  161.         say 'Error' rc '('turbotext.lasterror') while opening "'filename'"'
  162.         return
  163.     end
  164.     else do
  165.         port = result
  166.         call activateline(port,line)
  167.         return
  168.     end
  169.